<template>
  <div class="help">
    <!--问答-->
    <div class="page-container">
      <div class="container">
        <div class="row">
          <!--左边-->
          <div class="span8 page-content">
            <div>
              <h1>
                问答区<small>{{smallttle}}</small>
              </h1>
            </div>
            <ul class="tabs-nav">
              <li :class="pagelistquery.lable==='' && pagelistquery.tag===''?'active':''" @click="changeLabel('')">
                <a>全部</a>
              </li>
              <li
                v-for="(label,id) in lables"
                :key="id"
                :class="pagelistquery.lable===label?'active':''"
                @click="changeLabel(label)"
              >
                <a>{{label}}</a>
              </li>
              <li v-if="pagelistquery.tag!=''" class="active" @click="changeLabel('')">
                <a>{{pagelistquery.tag}}</a>
              </li>
            </ul>
            <section class="widget">
              <ul class="articles">
                <li class="article-entry standard" v-for="(item,id) in tableData" :key="id">
                  <h4>
                    <router-link :to="'/helpcontent/'+item.help_id">
                      {{item.help_title}}
                    </router-link>
                  </h4>
                  <span class="article-meta">
                    <a class="iconfont">&#xe619;</a>
                    {{item.createtime| dataFormat}}
                    <a
                      class="iconfont"
                      style="margin-left:50px"
                    >&#xe688;</a>{{item.nickname}}
                  </span>
                  <span class="like-count">
                    <a class="iconfont">&#xe61c;</a>{{item.help_read_num}}
                  </span>
                </li>
              </ul>
            </section>
            <!--页码-->
            <el-pagination
              @current-change="handleCurrentChange"
              layout="prev, pager, next"
              :total="pagelistquery.total"
            ></el-pagination>
          </div>
          <!--右边-->
          <aside class="span4 page-sidebar">
            <carousel/>
            <oldstuffhot/>
          </aside>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import carousel from '../components/carousel'
import oldstuffhot from '../components/oldstuffhot'

export default {
  name: 'help',
  components: {
    carousel,
    oldstuffhot
  },
  data () {
    return {
      smallttle: '',
      lables: [],
      pagelistquery: {
        lable: '',
        tag: '',
        total: 0,
        pagesize: 10,
        page: 1
      },
      tableData: {}
    }
  },
  props: { tag: {} },
  methods: {
    changeLabel (lable) {
      this.pagelistquery.lable = lable
      this.smallttle = this.pagelistquery.lable
      this.pagelistquery.tag = ''
      this.getHelpList()
    },
    changeTag () {
      this.pagelistquery.tag = this.tag
      this.smallttle = this.tag
    },
    handleCurrentChange (val) {
      this.pagelistquery.page = val
      this.getHelpList()
    },
    async getHelpList () {
      const result = await this.$axios.post('/web/gethelplist', this.qs.stringify(this.pagelistquery))
      if (result.data.state.type === 'SUCCESS') {
        this.tableData = result.data.data
        this.pagelistquery.total = result.data.count
      }
    },
    async getLabelList () {
      const result = await this.$axios.post('/admin/lablelist', this.qs.stringify({ lable_name: '问答分类' }))
      if (result.data.state.type === 'SUCCESS') {
        this.lables = JSON.parse(result.data.data[0].lable)
      }
    }
  },
  created () {
    this.tag && this.changeTag()
    this.getHelpList()
    this.getLabelList()
  }
}
</script>

<style scoped>
  .help {
    min-height: 200px;
  }
</style>
